//
//  SecondVc.m
//  F FloatingPlayer
//
//  Created by yonas on 2018/9/26.
//  Copyright © 2018年 Inspur. All rights reserved.
//

#import "SecondVc.h"
#import "FloatingViewModel.h"
#import "FloatingPlayerView.h"
@interface SecondVc ()
@property(nonatomic,weak) FloatingPlayerView *playerView;
@property(nonatomic,assign) BOOL hasView;
@end

@implementation SecondVc
- (instancetype)initWithNoView{
    if(self = [super init]){
        _hasView = YES;
    }
    return self;
}
- (instancetype)init{
    if (self = [super init]){
        
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];
    self.title = @"SecondVc";
    
    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1.jpg"]];
    imageView.frame = CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    [self.view addSubview:imageView];
    
    FloatingPlayerView *view = [[NSBundle mainBundle]loadNibNamed:@"FloatingPlayerView" owner:nil options:nil].lastObject;
    view.frame = CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width/16 * 9);
    [self.view addSubview:view];
    _playerView = view;
    if(_hasView){
        _playerView.hidden = YES;
    }
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 500, 50, 50)];
    btn.titleLabel.text = @"show";
    btn.titleLabel.textColor = [UIColor whiteColor];
    btn.backgroundColor = [UIColor redColor];
    [btn addTarget:self action:@selector(show) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
}
- (void)show{
    FloatingViewModel *model = [FloatingViewModel new];
    model.willShowView = _playerView;
    model.scale = 0.6;
    model.positionInsets = UIEdgeInsetsMake(0,0,1,1);
    model.positionOption = PositionOptionsAuto;
    model.fromVc = NSStringFromClass([self class]);
    [[NSNotificationCenter defaultCenter]postNotificationName:SHOW_FLOATING_VIEW object:model];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    if (_hasView){
        _playerView.hidden = NO;
    }
}
- (void)dealloc{
    NSLog(@"%s",__func__);
}
@end
